/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hr.cmi.android.aanwezigheidsregistratie;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import nl.hr.cmi.android.aanwezigheidsregistratie.adapter.StudentsDBAdapter;
import nl.hr.cmi.android.aanwezigheidsregistratie.helper.JSONHelper;

/**
 *
 * @author HP-laptop
 */
public class Hoofdscherm extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        // Puur om te testen.
        JSONHelper json = new JSONHelper();
        Log.e("NAMEN", json.getNamen().toString());

// <editor-fold defaultstate="collapsed" desc="onClick voor button registeren">
        final Button registerenbutton = (Button) findViewById(R.id.button_registreren);
        registerenbutton.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent(Constants.INTENT_ACTION_VIEW_INVOERMETHODE);
                startActivity(intent);
            }
        });// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="onClick voor button settings">
        final Button settingsbutton = (Button) findViewById(R.id.button_instellingen);
        settingsbutton.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
               // Intent intent = new Intent(Constants.INTENT_ACTION_VIEW_SETTING);
                Intent intent = new Intent("nl.hr.cmi.android.aanwezigheidsregistratie.VIEW_SETTING");
                startActivity(intent);
            }
        });// </editor-fold>

        // <editor-fold defaultstate="collapsed" desc="onClick voor button opslaan">
        final Button opslaanbutton = (Button) findViewById(R.id.button_opslaan);
        if (opslaanbutton != null) {
            opslaanbutton.setOnClickListener(new Button.OnClickListener() {

                public void onClick(View v) {
                    Log.e("Onclick", "Opslaan");
                    StudentsDBAdapter dbHelper = new StudentsDBAdapter(v.getContext());
                    dbHelper.open();

                    Cursor x = dbHelper.fetchNote(new Long("0764168").longValue());
                    Log.e("AANTAL regels", x.getCount() + "");
                    if (x.getCount() == 0) {
                        dbHelper.createNote(new Long("0764168").longValue(), "Johan Kom");
                    }
                    x = dbHelper.fetchNote(new Long("0764074").longValue());
                    if (x.getCount() == 0) {
                        dbHelper.createNote(new Long("0764074").longValue(), "Kevin van Ingen");
                    }

                    Cursor c = dbHelper.fetchAllNotes();
                    startManagingCursor(c);
                    String[] studenten = new String[]{StudentsDBAdapter.KEY_NAAM};

                    c.moveToFirst();
                    do {
                        String studentnummer = c.getString(0);
                        String naam = c.getString(1);
                        Log.e("DB_REGEL", studentnummer + " - " + naam);
                    } while (c.moveToNext());

                    Boolean updated = new Boolean(dbHelper.updateNote(new Long("0764168").longValue(), "JPWKOM"));
                    Log.e("UPDATE GELUKT?", updated.toString());

                    Boolean deleted = new Boolean(dbHelper.deleteNote(new Long("0764074").longValue()));
                    Log.e("DELETE GELUKT?", deleted.toString());
                }
            });
        }// </editor-fold>
    }
}
